#include "../DLLmain.h"

BOOL __fastcall PSPELLS_Init()
{
	std::copy(D2GAME_pSpellTable, D2GAME_pSpellTable + 11, Extend_pSpellTbl);

	Extend_pSpellTbl[16].GameFunc = &PSPELLS_SpawnPortal;

	return TRUE;
}

BOOL __fastcall PSPELLS_SpawnPortal(DWORD pGame, UnitAny* pPlayer, UnitAny* pItem, UnitAny* pTarget, int nX, int nY, int nSkill)
{
	auto pItemTxt = D2COMMON_GetItemText(pItem->dwTxtFileNo);
	if (!pItemTxt)
	{
		return FALSE;
	}

	int nDestMap = D2COMMON_EvalItemCalc(pPlayer, pItem, pItemTxt->dwCalc1);
	int nMapLimit = D2COMMON_EvalItemCalc(pPlayer, pItem, pItemTxt->dwCalc2);

	return OBJECTS_CreateRedPortal(pGame, pPlayer, nDestMap, nMapLimit);
}